package com.excilys.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Class that takes care of the login's form (see security-app-context.xml for
 * Spring security's configuration)
 * 
 * @author excilys dev : GF
 * 
 */
@Controller
public class LoginController {

	/**
	 * Displays the login form when needed / http request : GET / jsp response :
	 * login.jsp
	 * 
	 * @param model
	 */
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login(ModelMap model) {
		return "login";
	}

	/**
	 * Displays an error message in the login form when authentication fails /
	 * http request : GET / jsp response : login.jsp
	 * 
	 * @param model
	 */
	@RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
	public String loginerror(ModelMap model) {
		model.addAttribute("error", "true");
		return "login";
	}

	/**
	 * Logs the user out / http request : GET / jsp response : index.jsp
	 * 
	 * @param model
	 */
	@RequestMapping(value = "/logout", method = RequestMethod.GET)
	public String logout(ModelMap model) {
		return "login";
	}

}